package com.lck.blogmanager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lck.blogmanager.common.Response;
import com.lck.blogmanager.req.AddBlogCommentReq;
import com.lck.blogmanager.req.PageBlogCommentReq;
import com.lck.blogmanager.req.UserDeleteBlogCommentReq;
import com.lck.blogmanager.res.UserBlogCommentPageRes;
import com.lck.blogmanager.service.BlogCommentService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 博客评论
 * @author wyq
 * @version v1.0.0
 * @explain
 * @date 2024/4/7 18:29
 */
@RequestMapping("/blogComment")
@RequiredArgsConstructor
@Slf4j
@RestController
@CrossOrigin
public class BlogCommentController {

    private final BlogCommentService blogCommentService;

    /**
     * 博客添加评论
     * @param req
     * @return
     */
    @PostMapping("/add")
    public Response<Integer> addBlogComment(@RequestBody AddBlogCommentReq req){
        Integer commentId = blogCommentService.addBlogComment(req);
        return Response.success(commentId);
    }

    /**
     * 博客查询评论
     * @return
     */
    @PostMapping("/pageComment")
    public Response<Page<UserBlogCommentPageRes>> pageBlogComment(@RequestBody PageBlogCommentReq req){
        Page<UserBlogCommentPageRes> res = blogCommentService.pageBlogComment(req);
        return Response.success(res);
    }

    /**
     * 用户删除评论
     * @param req
     * @return
     */
    @PostMapping("/deleteComment")
    public Response deleteComment(@RequestBody UserDeleteBlogCommentReq req){
        blogCommentService.deleteComment(req);
        return Response.success();
    }


}
